#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int n,p,k;
int main()
{
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
		if (a[i] == i)
		{
			p++;
		}
	}
	//判断有没有交换两个数的情况
	for (int i = 0;i < n;i++)
	{
		//注意必须是i不等于a[i]才能这样判断
		if (i != a[i] && a[a[i]] == i)
		{
			k++;break;
		}
	}
	if (p == n) cout << p << endl;
	else if (k != 0) cout << p + 2 << endl;
	else cout << p + 1<<endl;
	return 0;
}